package com.genexususa.eo.bing.data.wsSubclasses;

import com.genexususa.eo.bing.CampaignManagementServiceClasses.BudgetLimitType;
import com.genexususa.eo.bing.CampaignManagementServiceClasses.Campaign;
import com.genexususa.eo.bing.CampaignManagementServiceClasses.CampaignStatus;
import com.genexususa.eo.bing.data.GxItemException;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

public class GxCampaign extends Campaign {
    private long gxId;

    public GxCampaign(Element element) throws IllegalArgumentException, GxItemException {
        if (element.getElementsByTagName("BudgetType").getLength() > 0 &&
            element.getElementsByTagName("BudgetType").item(0).getChildNodes().getLength() > 0) {
            this.setBudgetType(BudgetLimitType.fromString(((Node) element.getElementsByTagName("BudgetType").item(0).getChildNodes().item(0)).getNodeValue()));
        }
        if (element.getElementsByTagName("ConversionTrackingEnabled").getLength() > 0 &&
            element.getElementsByTagName("ConversionTrackingEnabled").item(0).getChildNodes().getLength() > 0) {
            this.setConversionTrackingEnabled(Boolean.valueOf(((Node)element.getElementsByTagName("ConversionTrackingEnabled").item(0).getChildNodes().item(0)).getNodeValue()));
        }
        if (element.getElementsByTagName("DailyBudget").getLength() > 0 &&
            element.getElementsByTagName("DailyBudget").item(0).getChildNodes().getLength() > 0 &&
            Double.valueOf(((Node)element.getElementsByTagName("DailyBudget").item(0).getChildNodes().item(0)).getNodeValue()) != 0) {
            this.setDailyBudget(Double.valueOf(((Node)element.getElementsByTagName("DailyBudget").item(0).getChildNodes().item(0)).getNodeValue()));
        }
        if (element.getElementsByTagName("DaylightSaving").getLength() > 0 &&
            element.getElementsByTagName("DaylightSaving").item(0).getChildNodes().getLength() > 0) {
            this.setDaylightSaving(Boolean.valueOf(((Node)element.getElementsByTagName("DaylightSaving").item(0).getChildNodes().item(0)).getNodeValue()));
        }
        if (element.getElementsByTagName("Description").getLength() > 0 &&
            element.getElementsByTagName("Description").item(0).getChildNodes().getLength() > 0) {
            this.setDescription(((Node)element.getElementsByTagName("Description").item(0).getChildNodes().item(0)).getNodeValue());
        }
        if (element.getElementsByTagName("GxCampaignId").getLength() > 0 &&
            element.getElementsByTagName("GxCampaignId").item(0).getChildNodes().getLength() > 0 &&
            Long.valueOf(((Node)element.getElementsByTagName("GxCampaignId").item(0).getChildNodes().item(0)).getNodeValue()) != 0) {
            this.gxId = Long.valueOf(((Node)element.getElementsByTagName("GxCampaignId").item(0).getChildNodes().item(0)).getNodeValue());
        } else {
            throw new GxItemException("Missing external campaign id");
        }
        if (element.getElementsByTagName("BingCampaignId").getLength() > 0 &&
            element.getElementsByTagName("BingCampaignId").item(0).getChildNodes().getLength() > 0 &&
            Long.valueOf(((Node)element.getElementsByTagName("BingCampaignId").item(0).getChildNodes().item(0)).getNodeValue()) != 0) {
            this.setId(Long.valueOf(((Node) element.getElementsByTagName("BingCampaignId").item(0).getChildNodes().item(0)).getNodeValue()));
        }
        if (element.getElementsByTagName("MonthlyBudget").getLength() > 0 &&
            element.getElementsByTagName("MonthlyBudget").item(0).getChildNodes().getLength() > 0 &&
            Double.valueOf(((Node)element.getElementsByTagName("MonthlyBudget").item(0).getChildNodes().item(0)).getNodeValue()) != 0) {
            this.setMonthlyBudget(Double.valueOf(((Node)element.getElementsByTagName("MonthlyBudget").item(0).getChildNodes().item(0)).getNodeValue()));
        }
        if (element.getElementsByTagName("Name").getLength() > 0 &&
            element.getElementsByTagName("Name").item(0).getChildNodes().getLength() > 0) {
            this.setName(((Node)element.getElementsByTagName("Name").item(0).getChildNodes().item(0)).getNodeValue());
        }
        if (element.getElementsByTagName("Status").getLength() > 0 &&
            element.getElementsByTagName("Status").item(0).getChildNodes().getLength() > 0) {
            if (((Node) element.getElementsByTagName("Status").item(0).getChildNodes().item(0)).getNodeValue().equals("A")) {
                this.setStatus(CampaignStatus.Active);
            } else if (((Node) element.getElementsByTagName("Status").item(0).getChildNodes().item(0)).getNodeValue().equals("BMP")) {
                this.setStatus(CampaignStatus.BudgetAndManualPaused);
            } else if (((Node) element.getElementsByTagName("Status").item(0).getChildNodes().item(0)).getNodeValue().equals("BP")) {
                this.setStatus(CampaignStatus.BudgetPaused);
            } else if (((Node) element.getElementsByTagName("Status").item(0).getChildNodes().item(0)).getNodeValue().equals("D")) {
                this.setStatus(CampaignStatus.Deleted);
            } else if (((Node) element.getElementsByTagName("Status").item(0).getChildNodes().item(0)).getNodeValue().equals("P")) {
                this.setStatus(CampaignStatus.Paused);
            }
        }
        if (element.getElementsByTagName("TimeZone").getLength() > 0 &&
            element.getElementsByTagName("TimeZone").item(0).getChildNodes().getLength() > 0) {
            this.setTimeZone(((Node)element.getElementsByTagName("TimeZone").item(0).getChildNodes().item(0)).getNodeValue());
        }
    }

    public long getGxId() {
        return gxId;
    }

    public void setGxId(long gxId) {
        this.gxId = gxId;
    }
}
